<?php

require_once("../common/conn.php");
require_once("../common/common.php");
if (isset($_GET['method'])) {
    $method = trim($_GET['method']);
    if ($method == "get") {
        $sql = "SELECT * FROM t_hibaby_resource_version ORDER BY os";
        $db = new DBC();
        $data = $db->fetchData($sql);
        echo json_encode($data);
    } else if ($method == "set") {
        $data = $_GET['data'];
        $array = json_decode($data, true);
        $return = false;
        if (checkArrayNotEmpty($array)) {
            $db = new DBC();
            $sql = "DELETE FROM t_hibaby_resource_version";
            $return = $db->execute($sql);
            //  名称 	  版本 	操作系统 	URL
            foreach ($array as $row) {
                $sql = "INSERT INTO t_hibaby_resource_version(name,os,version,url) VALUES('" . $row['name'] . "','" . $row['os'] . "','" . $row['version'] . "','" . $row['url'] . "')";
                if (!$db->execute($sql)) {
                    $return = false;
                }
            }
        }
        echo json_encode($return);
    }
}
?>
